# Author: Xianyan

# 字典是另一种可变容器模型，且可存储任意类型对象。
# 字典的每个键值 key=>value 对用冒号 : 分割，每个键值对之间用逗号 , 分割，整个字典包括在花括号 {} 中

# 语法

info = {
    "stu1901":"Xiaoyan",
    "stu1902":"Guijun",
    "stu1903":"Xiaobing"
}
print(info)

#创建字典的常用方法

info1 = {
    "stu1901":"Xiaoyan",
    "stu1902":"Guijun",
    "stu1903":"Xiaobing"
}

print(info1)

info2 = dict(stu1901="Xiaoyan",stu1902="Guijun",stu1903="Xiaobing")
print(info2)

info3 = {}
info3["stu1901"]="Xiaoyan"
info3["stu1902"]="Guijun"
info3["stu1903"]="Xiaobing"
print(info3)

# 增加
info["stu1904"] = "Damao"
print(info)

# 修改
info["stu1904"] = "Miaomiao"
print(info)

# 删除
info.pop("stu1904") #标准删除姿势
print(info)

del info["stu1901"] #换个姿势删除
print(info)

#随机删除
info = {"stu1901":"Xiaoyan","stu1902":"Guijun","stu1903":"Xiaobing"}
print(info)
info.popitem()
print(info)

# 查找
info = {"stu1901":"Xiaoyan","stu1902":"Guijun","stu1903":"Xiaobing"}
info
print("stu1901" in info) #标准用法

print(info.get("stu1902")) #获取

print(info["stu1902"]) #同上，但看下面

KeyError: 'stu1905'
print(info.get("stu1905"))
